package br.ufc.great.dtx.tm.sch;

import br.ufc.great.dtx.server.DTXOutput;

public class AlertDaemon extends Thread {

	private Scheduler s;
	private SchedulerRemoteOperation sro;
	private SchedulerRemoteMessage srm;
	private SchedulerRemoteWFGMessage srwfgm;
	private DTXOutput output;
	
	public AlertDaemon(DTXOutput output, Scheduler s, SchedulerRemoteOperation sro, SchedulerRemoteMessage srm, SchedulerRemoteWFGMessage srwfgm) {
		this.output = output;
		this.s = s;
		this.sro = sro;
		this.srm = srm;
		this.srwfgm = srwfgm;
		setPriority(MIN_PRIORITY);
	}
	
	public void run() {
		while (true) {
			output.setTransactionBufferSize(s.size());
			output.setRemoteOperationBufferSize(sro.size());
			output.setRemoteMessageBufferSize(srm.size());
			if (s.size() > 0) {
				s.restart();
			}
			if (sro.size() > 0) {
				sro.restart();
			}
			if (srm.size() > 0) {
				srm.restart();
			}
			if (srwfgm.size() > 0) {
				srwfgm.restart();
			}
			//output.print(getClass().getSimpleName(), "processed", DTXOutput.HIGHLIGHT);
			try {
				sleep(1 * 1000 * 4);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
}
